﻿/*******************************************************************************
* file  : bit map
* creat : apleilx
* data  : 2017/03/02
*******************************************************************************/
#include "common.h"
#include "crc_ext.h"
#include "bsp_api.h"
#include "swap.h"


void swap_bit_map_u8_multi(void *p_src, void *p_des, size_t groups);
void swap_bit_map_u16_multi(void *p_src, void *p_des, size_t groups);
void swap_bit_map_u32_multi(void *p_src, void *p_des, size_t groups);
void swap_bit_map_u32_alloc_multi(void *p_src, void *p_des, size_t groups);

#define dat_buff_init() loop_n(1000) src[index] = index*1919; \
memset(enc,0,2000); \
memset(dec,0,2000); \
	
/*******************************************************************************
* @brief  bit map.
* \param[in] none
* \retval: none
*******************************************************************************/
void bit_map_demo(void)
{
	uu16 *src, *enc, *dec;
	
	src = malloc(2048);
	enc = malloc(2048);
	dec = malloc(2048);
	
	dbg_puts("bit map u8 , group 6 =>\n");
	dat_buff_init();
	swap_bit_map_u8_multi(src, enc, 6);
	swap_bit_map_u8_multi(enc, dec, 6);
	
	dbg_u16_print("src: \n", src, 30, 32);
	dbg_u16_print("enc: \n", enc, 30, 32);
	dbg_u16_print("dec: \n", dec, 30, 32);
	
	dbg_puts("bit map u16 , group 2 =>\n");
	dat_buff_init();
	swap_bit_map_u16_multi(src, enc, 2);
	swap_bit_map_u16_multi(enc, dec, 2);
	
	dbg_u16_print("src: \n", src, 36, 32);
	dbg_u16_print("enc: \n", enc, 36, 32);
	dbg_u16_print("dec: \n", dec, 36, 32);
	
	dbg_puts("bit map u32 , group 2 =>\n");
	dat_buff_init();
	swap_bit_map_u32_alloc_multi(src, enc, 2);
	swap_bit_map_u32_alloc_multi(enc, dec, 2);
	
	dbg_u16_print("src: \n", src, 132, 32);
	dbg_u16_print("enc: \n", enc, 132, 32);
	dbg_u16_print("dec: \n", dec, 132, 32);
	
	dat_buff_init();
	swap_bit_map_bn_multi(src, enc, 99, 1);
	swap_bit_map_bn_multi(enc, dec, 99, 1);
	dbg_u16_print("src: ", src, 32, 40);
	dbg_u16_print("enc: ", enc, 32, 40);
	dbg_u16_print("dec: ", dec, 32, 40);
	dbg_u16_print("src: ", src+848/2, 32, 40);
	dbg_u16_print("enc: ", enc+848/2, 32, 40);
	dbg_u16_print("dec: ", dec+848/2, 32, 40);
	
	free(src);
	free(enc);
	free(dec);
}
